Skip to content

Resolve empty SQLServer aggregate column labels during result merge (#23799) - #40584

Merged
terrymanu merged 1 commit into
apache:masterfrom
Forry-xrm:fix-23799
Dec 4, 2026
Merged

terrymanu merged 1 commit into
apache:masterfrom
Forry-xrm:fix-23799

Conversation

@Forry-xrm

Copy link
Copy Markdown
Contributor

Fixes #23799.

Background

SQLServer JDBC returns an empty column label for aggregate columns without aliases, so sharded select count(1) from t_order failed during result merge with:
java.lang.IllegalStateException: Can't find index: AggregationProjection(...), please add alias for aggregate selections.

Change

Following the maintainer-accepted direction, ShardingDQLResultMerger now builds the column-label index map with a SQLServer-scoped fallback for empty labels: column label -> JDBC column name -> the positionally aligned expanded projection's column label, so the key matches the label that setIndexForAggregationProjection derives from the same AggregationProjection. Non-SQLServer protocols and non-empty labels keep the previous behavior unchanged.

  • Affected files:
    • features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMerger.java
    • features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/ShardingDQLResultMergerTest.java

Verification

  • New unit test assertBuildGroupByMemoryMergedResultWithSQLServerEmptyColumnLabel simulates SQLServer metadata with an empty label/name; the focused test class passes 33/33.
  • Negative control: reverting only the production change makes the new test fail with the exact reported exception.
  • Module-wide spotless:check checkstyle:check -Pcheck passes with 0 Checkstyle violations.

AI assistance

Implemented with AI assistance; the change scope and affected files are listed above.

@terrymanu terrymanu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The local candidate adds regression tests for SELECT *, AVG-derived columns, and multiple aggregates, verifying assigned column indexes and complete merged results. The increases in three existing complexity warnings are retained under explicit user authorization for this task only.

Result

Review Result: Mergeable

No blocking issues or required changes remain.

Evidence

  • All 36 tests passed; all three new tests detect the original defect.
  • Spotless and Checkstyle both exited 0 and covered both changed files.
  • The quality scanner exited 1 solely for an existing, unchanged, unrelated helper diagnostic; no new diagnostics were introduced.
  • Two independent complete reviews and final review-session validation passed.

Coverage

Public head b3b21a0 plus uncommitted local changes in two files. The complete PR and local delta were reviewed.
This is a code-scope conclusion; CI was not reviewed.

@terrymanu terrymanu added this to the 5.5.4 milestone Dec 4, 2026
@terrymanu
terrymanu merged commit f5ecbce into apache:master Dec 4, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No result from sql: "select count(1) from t_order"

3 participants